home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asmexam.arc / PASSWORD.LST < prev    next >
Encoding:
File List  |  1983-11-17  |  12.5 KB  |  282 lines

  1.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-1
  2.  
  3.  
  4.  
  5.                             page 55,132
  6.                     ;------------------------------------------------------------------------------
  7.                     ;PASSWORD.ASM (creates PWORD.SYS, device driver)
  8.                     ;
  9.                     ;DOS 2.00 Device driver forces user to enter password on booting up
  10.                     ;and disables Ctrl-Break.
  11.                     ;
  12.                     ;After assembly: link PASSWORD (ignore "no STACK" error)
  13.                     ;                exec2bin PASSWORD PASSWORD.SYS
  14.                     ;                place DEVICE=PASSWORD.SYS in CONFIG.SYS file
  15.                     ;                reboot system with Ctrl-Alt-Del
  16.                     ;                answer prompt with: PassWord <enter>
  17.                     
  18.  0000                   dev_seg      segment
  19.  0000                   pword_device proc far
  20.                                  assume cs:dev_seg,ds:dev_seg,es:dev_seg
  21.                     
  22.                     ;-------------------------------
  23.                     ;The following lines are the device header, which must exist for
  24.                     ;every device.  This file has only one device, and it works with
  25.                     ;character I/O.  It doesn't actually handle any I/O services,
  26.                     ;but it's easier to create a character device.
  27.                     
  28.  0000                   pword_dev_header:   ;label for the start of the device driver
  29.                     
  30.  0000  FF FF FF FF         next_dev_ptr       dd -1               ;only 1 device is defined in this file
  31.  0004  8000              dev_attribute      dw 8000h            ;character device (simpler that way)
  32.  0006  0070 R              strategy_ptr       dw  strategy        ;the installation proc
  33.  0008  007B R              interrupt_ptr      dw  interrupt       ;the proc that handles all service requests
  34.  000A  50 41 53 53 57 4F    device_name        db  'PASSWORD'      ;8-byte string of device name
  35.        52 44              
  36.                     
  37.                     ;--- This is the stroage area for the password --
  38.                     ;--- The first byte is the length (0-16) --------
  39.                     ;--- The following characters are the password --
  40.                     ;--- Only an exact match will allow the system --
  41.                     ;--- to continue the boot process ---------------
  42.                     
  43.  0012  08 50 61 73 73 57    password_store     db 8,'PassWord'
  44.        6F 72 64              
  45.  001B     09 [                                 db $-password_store dup(' ')       ;leave room for a
  46.                 20         
  47.                     ]         
  48.                     
  49.                                                                           ;16 character password
  50.                     
  51.  0024  10              in_buf_max  db 16        ;input buffer for reading password from user
  52.  0025  ??              in_buf_len  db ?         ;it is set up for DOS service OAH, BUFFERED_INPUT
  53.  0026     10 [              in_buf      db 16 dup(?)
  54.                 ??         
  55.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-2
  56.  
  57.  
  58.  
  59.                     ]         
  60.                     
  61.                     
  62.                     ;----- The STRATEGY proc stores ES:BX request header pointer here
  63.                     ;----- The INTERRUPT proc retrieves it
  64.                     
  65.  0036                   request_ptr label dword                ;defined as double word for LES opcode
  66.  0036  ????              req_ptr_off dw  ?                      ;and as two words for MOV opcodes
  67.  0038  ????              req_ptr_seg dw  ?
  68.                     
  69.                     
  70.                     
  71.  003A                   dummy_iret:                            ;Ctrl-Break vector is pointed here, so it
  72.  003A  CF                          iret                       ;does nothing.  Break is not recognized.
  73.                     
  74.                     
  75.                     
  76.                     ;------------------messages----------------------------------------------------
  77.                     ;These messages are expected to be output via the ANSI.SYS device,
  78.                     ;so it should be installed (named in the CONFIG.SYS file) before
  79.                     ;this PWORD device.
  80.                     ;If you don't want to use ANSI.SYS, remove the ESC sequences in the messages.
  81.                     
  82.  = 000A                             lf  equ 0ah
  83.  = 000D                             cr  equ 0dh
  84.  = 001B                             esc equ 1bh
  85.                     
  86.  003B  0D 0A 1B 5B 30 6D    msg_1         db cr,lf,esc,'[0m'                 ;make output visible
  87.  0041  45 6E 74 65 72 20                  db 'Enter Password: '
  88.        50 61 73 73 77 6F    
  89.        72 64 3A 20         
  90.  0051  1B 5B 38 6D 24                       db esc,'[8m$'                     ;make input invisible
  91.                     
  92.  0056  0D 0A 1B 30 6D         msg_2         db cr,lf,esc,'0m'                  ;make output visible
  93.  005B  50 61 73 73 77 6F                  db 'Password accepted.',cr,lf,'$'
  94.        72 64 20 61 63 63    
  95.        65 70 74 65 64 2E    
  96.        0D 0A 24              
  97.                     
  98.                     
  99.                     
  100.                     ;==============================================================================
  101.                     ;STRATEGY procedure
  102.                     ;Just saves the request header pointer for the INTERRUPT proc
  103.                     
  104.  0070                   strategy       proc far
  105.                                    assume cs:dev_seg
  106.                     
  107.  0070  2E: 89 1E 0036 R                        mov  cs:req_ptr_off,bx
  108.  0075  2E: 8C 06 0038 R                        mov  cs:req_ptr_seg,es
  109.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-3
  110.  
  111.  
  112.  
  113.  007A  CB                             ret                                ;far return to DOS
  114.  007B                   strategy       endp
  115.                     
  116.                     
  117.                     
  118.                     ;==============================================================================
  119.                     ;INTERRUPT procedure
  120.                     ;Processes the command indicated in the request header.
  121.                     
  122.  007B                   interrupt     proc far
  123.                                   assume cs:dev_seg,ds:nothing, es:nothing
  124.  007B  1E                            push       ds                      ;preserve all registers
  125.  007C  06                            push       es
  126.  007D  50                            push       ax
  127.  007E  53                            push       bx
  128.  007F  51                            push       cx
  129.  0080  52                            push       dx
  130.  0081  57                            push       di
  131.  0082  56                            push       si
  132.  0083  8C C8                            mov        ax,cs                   ;make DS address the
  133.  0085  8E D8                            mov        ds,ax                   ;program data area
  134.                     
  135.  0087  2E: C4 1E 0036 R                       les        bx,request_ptr          ;get the pointer saved by
  136.  008C  26: 8A 47 02                       mov        al,es:[bx+2]            ;fetch the command
  137.  0090  3C 00                            cmp        al,0
  138.  0092  74 15                            je         init_fn                 ;only valid request in INI
  139.  0094                   error_exit:
  140.  0094  26: 81 4F 03 8003                  or         word ptr es:[bx+3],8003H       ;indicate error cod
  141.                                                                             ;"Unknown command"
  142.                     
  143.                     ;---- interrupt service request has been handled.
  144.                     ;---- Set he "done flag" and return to DOS.
  145.                     
  146.  009A                   common_exit:
  147.  009A  26: 81 4F 03 0100                  or         word ptr es:[bx+3],100H        ;set the done bit
  148.  00A0  5E                            pop        si
  149.  00A1  5F                            pop        di
  150.  00A2  5A                            pop        dx
  151.  00A3  59                            pop        cx
  152.  00A4  5B                            pop        bx
  153.  00A5  58                            pop        ax
  154.  00A6  07                            pop        es
  155.  00A7  1F                            pop        ds
  156.  00A8  CB                            ret                 ;far return
  157.                     
  158.                     
  159.                     ;---- Only the INIT function is handled by the PWORD device
  160.                     ;---- all other requests are routed through the error_exit.
  161.                     
  162.                     ;----------------------------------
  163.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-4
  164.  
  165.  
  166.  
  167.                     ;INIT_FN procedure
  168.                     ;prompts the user for a password, keeps prompting until correct entry
  169.                     ;received,  Passes the address of this proc back to DOS as the end-of-driver
  170.                     ;address so that a minimum amount of storage is used.
  171.                     
  172.  00A9                   init_fn       proc near
  173.                     
  174.  00A9  06                            push       es
  175.                     
  176.                     ;--------------
  177.                     ;The following 4 lines eliminate Ctrl-Break from having
  178.                     ;any effect on the system, unless another program
  179.                     ;KEYBOARD_BREAK vector is altered (BASIC does that).
  180.                     
  181.  00AA  B8 0000                            mov        ax,0
  182.  00AD  8E C0                            mov        es,ax
  183.  00AF  26: C7 06 006C 003A R                  mov        word ptr es:[1Bh*4],offset dummy_iret
  184.  00B6  26: 8C 0E 006E                       mov        word ptr es:[1Bh*4+2],cs
  185.  00BB  EB 06                            jmp        short no_beep
  186.  00BD                   try_again:
  187.  00BD  B0 07                            mov        al,7     ;bel character
  188.  00BF  B4 0E                            mov        ah,0EH   ;WRITE_TTY service
  189.  00C1  CD 10                            int        10h
  190.  00C3                   no_beep:
  191.  00C3  BA 003B R                       mov        dx,offset msg_1         ;"Enter Password:"
  192.  00C6  B4 09                            mov        ah,9                    ;DOS print string service
  193.  00C8  CD 21                            int        21H
  194.                     
  195.  00CA  BA 0024 R                       mov        dx,offset in_buf_max
  196.  00CD  B4 0C                            mov        ah,0Ch                  ;clear input buffer and..
  197.  00CF  B0 0A                            mov        al,0Ah                  ;input a line of character
  198.  00D1  CD 21                            int        21H
  199.  00D3  8C C8                            mov        ax,cs
  200.  00D5  8E C0                            mov        es,ax                   ;set ES to target password
  201.                                                                      ;DS already points to user
  202.  00D7  BE 0025 R                       mov        si,offset in_buf_len
  203.  00DA  B5 00                            mov        ch,0
  204.  00DC  8A 0C                            mov        cl,[si]
  205.  00DE  3A 0D                            cmp        cl,[di]                 ;are lengths the same?
  206.  00E0  75 DB                            jne        try_again
  207.  00E2  47                            inc        di                      ;point to first characters
  208.  00E3  46                            inc        si                      ;of both strings
  209.  00E4  F3/ A6                            rep cmpsb                          ;all chars the same?
  210.  00E6  75 D5                            jne        try_again               ;no, start over
  211.                     
  212.  00E8  BA 0056 R                       mov        dx,offset msg_2 ;"Password accepted"
  213.  00EB  B4 09                            mov        ah,9
  214.  00ED  CD 21                            int        21H
  215.                     
  216.                     ;---- now exit from INIT procedure -----------------------------
  217.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-5
  218.  
  219.  
  220.  
  221.                     ;---- retain only the minimum amount of code -------------------
  222.                     ;---- to handle erroneous service requests ---------------------
  223.                     
  224.  00EF  07                            pop        es
  225.  00F0  26: C7 47 0E 00A9 R                  mov        word ptr es:[bx+0EH],offset init_fn
  226.  00F6  26: 8C 4F 10                       mov        word ptr es:[bx+10H],cs
  227.                     
  228.                     
  229.  00FA  EB 9E                           jmp        common_exit
  230.  00FC                   init_fn      endp
  231.                     
  232.  00FC                   interrupt    endp
  233.  00FC                   pword_device endp
  234.  00FC                   dev_seg      ends
  235.                                  end        pword_dev_header        ;must specify end for EXE2
  236.  
  237.  The Microsoft MACRO Assembler             11-17-83        PAGE    Symbols-1
  238.  
  239.  
  240.  
  241. Segments and groups:
  242.  
  243.          N a m e              Size    align    combine    class
  244.  
  245. DEV_SEG. . . . . . . . . . . . .    00FC    PARA      NONE    
  246.  
  247. Symbols:            
  248.  
  249.          N a m e              Type    Value    Attr         
  250.  
  251. COMMON_EXIT. . . . . . . . . . .    L NEAR     009A    DEV_SEG
  252. CR . . . . . . . . . . . . . . .    Number    000D    
  253. DEVICE_NAME. . . . . . . . . . .    L BYTE     000A    DEV_SEG
  254. DEV_ATTRIBUTE. . . . . . . . . .    L WORD     0004    DEV_SEG
  255. DUMMY_IRET . . . . . . . . . . .    L NEAR     003A    DEV_SEG
  256. ERROR_EXIT . . . . . . . . . . .    L NEAR     0094    DEV_SEG
  257. ESC. . . . . . . . . . . . . . .    Number    001B    
  258. INIT_FN. . . . . . . . . . . . .    N PROC    00A9    DEV_SEG    Length =0053
  259. INTERRUPT. . . . . . . . . . . .    F PROC    007B    DEV_SEG    Length =0081
  260. INTERRUPT_PTR. . . . . . . . . .    L WORD     0008    DEV_SEG
  261. IN_BUF . . . . . . . . . . . . .    L BYTE     0026    DEV_SEG    Length =0010
  262. IN_BUF_LEN . . . . . . . . . . .    L BYTE     0025    DEV_SEG
  263. IN_BUF_MAX . . . . . . . . . . .    L BYTE     0024    DEV_SEG
  264. LF . . . . . . . . . . . . . . .    Number    000A    
  265. MSG_1. . . . . . . . . . . . . .    L BYTE     003B    DEV_SEG
  266. MSG_2. . . . . . . . . . . . . .    L BYTE     0056    DEV_SEG
  267. NEXT_DEV_PTR . . . . . . . . . .    L DWORD    0000    DEV_SEG
  268. NO_BEEP. . . . . . . . . . . . .    L NEAR     00C3    DEV_SEG
  269. PASSWORD_STORE . . . . . . . . .    L BYTE     0012    DEV_SEG
  270. PWORD_DEVICE . . . . . . . . . .    F PROC    0000    DEV_SEG    Length =00FC
  271. PWORD_DEV_HEADER . . . . . . . .    L NEAR     0000    DEV_SEG
  272. REQUEST_PTR. . . . . . . . . . .    L DWORD    0036    DEV_SEG
  273. REQ_PTR_OFF. . . . . . . . . . .    L WORD     0036    DEV_SEG
  274. REQ_PTR_SEG. . . . . . . . . . .    L WORD     0038    DEV_SEG
  275. STRATEGY . . . . . . . . . . . .    F PROC    0070    DEV_SEG    Length =000B
  276. STRATEGY_PTR . . . . . . . . . .    L WORD     0006    DEV_SEG
  277. TRY_AGAIN. . . . . . . . . . . .    L NEAR     00BD    DEV_SEG
  278.  
  279. Warning Severe
  280. Errors    Errors 
  281. 0    0
  282.